<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
		<title>后台管理</title>
		<style>
			
		</style>
	</head>
	<body>
		<p>未登录</p>
		<div class="updateJilu">
			<input type="text" class="jilu">
			<button class="updateJiLuBtn">发表记录</button>
		</div>
		<div class="updatePage">
			<input type="text" class="pageTitle">
			<textarea class="page"></textarea>
			<button class="updatePageBtn">发表文章</button>
		</div>
		<div class="updateImg">
			<input type="file">
			<button class="updateImgBtn">上传图片</button>
		</div>
	</body>
	<script src="../ajax.js"></script>
	<script>
		window.onload = function(){
		function $(el){
			return document.querySelector(el)
		}
		var p = $('p')
		var updateJilu = $('.updateJilu')
		var updatePage = $('.updatePage')
		var updateImg = $('.updateImg')
		console.log(document.cookie)
		var token = document.cookie.slice(6)
		console.log(token)
		ajax({
			url:'http://localhost:3000/userToken',
			type:'POST',
			async:true,
			data:{
			},
			token,
			success:function(data){
				console.log(data)
				dataJson = JSON.parse(data)
				p.innerHTML = dataJson[0].name
				
			}
		})
		var updateJiLuBtn = $('.updateJiLuBtn')
		var updatePageBtn = $('.updatePageBtn')
		updateJiLuBtn.onclick = function(){
			var jilu = $('.jilu').value
			console.log(typeof(jilu))
			ajax({
				url:'http://localhost:3000/addJiLu',
				type:'POST',
				async:true,
				data:{
					jiluContent:jilu
				},
				success:function(data){
					console.log(data)
				},
				token
			})
		}
		updatePageBtn.onclick = function(){
			var page = $('.page').value.toString()
			var pageTitle = $('.pageTitle').value.toString()
			ajax({
				url:'http://localhost:3000/addPage',
				type:'POST',
				async:true,
				data:{
					pageTitle,
					pageContent:page
				},
				success:function(data){
					console.log(data)
				},
				token
			})
		}
		
		// console.log(p.innerHTML)
		// if(p.innerHTML === '未登录'){
		// 	console.log(updateJilu)
		// 	updateJilu.style.display = 'none'
		// 	updatePage.style.display = 'none'
		// 	updateImg.style.display = 'none'
		// }
		
		}
	</script>
</html>
